package com.softgroup.breath.easyecgproject.utils;


import android.content.Context;
import android.content.SharedPreferences;

import com.softgroup.breath.easyecgproject.activity.CrashApplication;

public class SettingManager {
    private final String TAG = SettingManager.class.getSimpleName();
    private static SettingManager settingManager;
    private SharedPreferences sharedPreferences;

    private SettingManager() {
        sharedPreferences = CrashApplication.getInstance().getSharedPreferences("easy_ecg", Context.MODE_PRIVATE);
    }

    public static SettingManager getInstance() {
        if (settingManager == null) {
            synchronized (SettingManager.class) {
                if (settingManager == null) {
                    settingManager = new SettingManager();
                    settingManager.setSessionId("26866ddea7984d4387c769b66aae8a41");
                    settingManager.setUser("ee42015e7e2441ccac");
                }
            }
        }
        return settingManager;
    }

    public void setSessionId(String sessionId) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("session_id", sessionId);
        editor.commit();
    }

    public String getSessionID() {
        return sharedPreferences.getString("session_id", "26866ddea7984d4387c769b66aae8a41");
    }

    public void setGPS(double x, double y) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("x", x + "");
        editor.putString("y", y + "");
        editor.commit();
    }

    public double getGPSx() {
        double gpsx = Double.valueOf(sharedPreferences.getString("x", "37.800"));
        return gpsx;
    }

    public double getGPSy() {
        double gpsy = Double.valueOf(sharedPreferences.getString("x", "112.5800"));
        return gpsy;
    }

    public String getUser() {
        return sharedPreferences.getString("user_id", "ee42015e7e2441ccac");
    }


    public void setUser(String user) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("user_id", user);
        editor.commit();
    }

    public int getTestDuration() {
        return sharedPreferences.getInt("test_duration", 30);
    }

    public void setTestDuration(int testDuration) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("test_duration", testDuration);
        editor.commit();
    }

    public String getUserName() {
        return sharedPreferences.getString("user_name", "王鑫进");
    }

    public void setUserName(String userName) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("user_name", userName);
        editor.commit();
    }

    public String getUserSex() {
        return sharedPreferences.getString("user_sex", "男");
    }

    public void setUserSex(String userSex) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("user_sex", userSex);
        editor.commit();
    }

    public String getUserAge() {
        return sharedPreferences.getString("user_age", "26");
    }

    public void setUserAge(String userAge) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("user_age", userAge);
        editor.commit();
    }

}
